package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.ktgj.customer.domain.BusinessRefund;
import com.ktgj.customer.service.IBusinessRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 退续费订单Controller
 * 
 * @author ruoyi
 * @date 2021-09-15
 */
@ControllerAdvice
@RestController
@RequestMapping("/refund")
public class BusinessRefundController extends BaseController
{
    @Autowired
    private IBusinessRefundService businessRefundService;

    /**
     * 查询退续费订单列表
     */
    //@PreAuthorize(hasPermi = "system:refund:list")
    @GetMapping("/list")
    public TableDataInfo list(BusinessRefund businessRefund)
    {
        startPage();
        List<BusinessRefund> list = businessRefundService.selectBusinessRefundList(businessRefund);
        return getDataTable(list);
    }

    /**
     * 导出退续费订单列表
     */
    //@PreAuthorize(hasPermi = "system:refund:export")
    @Log(title = "退续费订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessRefund businessRefund) throws IOException
    {
        List<BusinessRefund> list = businessRefundService.selectBusinessRefundList(businessRefund);
        ExcelUtil<BusinessRefund> util = new ExcelUtil<BusinessRefund>(BusinessRefund.class);
        util.exportExcel(response, list, "退续费订单数据");
    }

    /**
     * 获取退续费订单详细信息
     */
    //@PreAuthorize(hasPermi = "system:refund:query")
    @GetMapping(value = "/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return AjaxResult.success(businessRefundService.selectBusinessRefundById(refundId));
    }

    /**
     * 新增退续费订单
     */
    //@PreAuthorize(hasPermi = "system:refund:add")
    @Log(title = "退续费订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessRefund businessRefund)
    {
        return toAjax(businessRefundService.insertBusinessRefund(businessRefund));
    }

    /**
     * 修改退续费订单
     */
    //@PreAuthorize(hasPermi = "system:refund:edit")
    @Log(title = "退续费订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessRefund businessRefund)
    {
        return toAjax(businessRefundService.updateBusinessRefund(businessRefund));
    }

    /**
     * 删除退续费订单
     */
    //@PreAuthorize(hasPermi = "system:refund:remove")
    @Log(title = "退续费订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(businessRefundService.deleteBusinessRefundByIds(refundIds));
    }
}
